package com.itheima.solr.test;

import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.junit.Test;

import java.io.IOException;

public class SolrTestDelete {
    /**
     * 按id删除
     * @throws IOException
     * @throws SolrServerException
     */
    @Test
    public void testWrite1() throws IOException, SolrServerException {
        //连接solr服务器
        HttpSolrServer httpSolrServer = new HttpSolrServer("http://localhost:8080/solr/test");
        httpSolrServer.deleteById("1");
        httpSolrServer.commit();

    }

    /**
     * 按查询条件删除
     */
    @Test
    public void test2() throws IOException, SolrServerException {
        //连接solr服务器
        HttpSolrServer solrServer = new HttpSolrServer("http://localhost:8080/solr/test");
        solrServer.deleteByQuery("title:荣威汽车");
        solrServer.commit();
    }
}
